package com.paradogs.gs.modules.world.entity;

import com.paradogs.gs.modules.WorldObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

/**
 * @author: yumi
 * @date: 2025/3/31  16:52
 * @Description: 世界
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BigWorld {

    private Integer id;
    private Map<String, WorldNode> nodeMap;

    // 离开
    public void leave(WorldObject object, int x, int y) {
        if (!hasNode(x, y)) {
            return;
        }
        WorldNode node = nodeMap.get(WorldNode.key(x, y));
        node.leave(object);
    }

    // 进入
    public void enter(WorldObject object, int x, int y) {
        if (!hasNode(x, y)) {
            return;
        }
        WorldNode node = nodeMap.get(WorldNode.key(x, y));
        object.setWorldId(this.id);
        node.enter(object);
    }

    public boolean hasNode(int x, int y) {
        return nodeMap.containsKey(WorldNode.key(x,y));
    }

}
